from collections import defaultdict

from common.mssql_helper import g_msql_inst
from common.utils import create_uuid, format_float

__author__ = "Ypf"
_date_ = "2019/8/22-15:48"



class SkjllrHs(object):
    @staticmethod
    def get_dic_skjllrhs(sql):
        res_list1 = g_msql_inst.fetch_all(sql)
        dic = defaultdict(dict)
        for (ghdw,hth,ckrq,cjbjdh,pp,cpmc,ggxh,bz,sfsl,xsdj,ssje,jlbl,jle,scjj,scjj1,scjj2,lkrq,bm,ywy,jsfs,sl,dwcb,cb,bhsml) in res_list1:
            id=create_uuid()
            if cjbjdh == None:
                dic[id] = [ghdw, hth, ckrq, cjbjdh, pp, cpmc, ggxh, bz, sfsl, format_float(xsdj), format_float(ssje),
                           0.3, format_float(ssje)*0.3, format_float(ssje)*0.3*0.4, format_float(ssje)*0.3*0.3, format_float(ssje)*0.3*0.3, lkrq,
                           bm, ywy, jsfs, format_float(sl), format_float(dwcb), format_float(cb), format_float(bhsml)]
            else:
                dic[id] = [ghdw,hth,ckrq,cjbjdh,pp,cpmc,ggxh,bz,sfsl,format_float(xsdj),format_float(ssje),format_float(jlbl),format_float(jle),format_float(scjj),format_float(scjj1),scjj2,lkrq,bm,ywy,jsfs,format_float(sl),format_float(dwcb),format_float(cb),format_float(bhsml)]
        return dic

    @staticmethod
    def insert_skjllrhs(dic, db_insert_sql, nowtime):
        for key in dic:
            id = create_uuid()
            dic[key].append(nowtime + '-01')
            dic[key].append(id)
            value_tuple = tuple(dic[key])
            excuete_sql = db_insert_sql % value_tuple
            print(excuete_sql)
            g_msql_inst.db_excuete(excuete_sql)